//
//  BusinessSettledController.m
//  ScalperMerchant
//
//  Created by 王云 on 2017/10/6.
//  Copyright © 2017年 WY. All rights reserved.
//

#import "BusinessSettledController.h"
#import "TextView.h"
//#import "CBPointController.h"
#import "SCLocationController.h"
#import "ZYQAssetPickerController.h"
#import "ALActionSheetView.h"
#import "DataPickView.h"
#import "BusinessTypeController.h"
#import "UIViewController+JTNavigationExtension.h"

@interface BusinessSettledController ()<UITextFieldDelegate,UINavigationControllerDelegate, UIImagePickerControllerDelegate,ZYQAssetPickerControllerDelegate>


@property (nonatomic,weak)TextView *TextV;

@property (nonatomic,weak)UITextField *shopAddressF;
@property (nonatomic,weak)UIButton *AddressB;

@property (nonatomic,weak)UIButton *ManagementB;
//店铺
@property (nonatomic,weak)UIButton *updateB;
//身份证正面
@property (nonatomic,weak)UIButton *positiveB;
//身份证反面
@property (nonatomic,weak)UIButton *negativeB;
//营业执照
@property (nonatomic,weak)UIButton *elcB;


@property (nonatomic,weak)TextView *textTV;
@property (nonatomic,weak)UIButton *SubmitBtn;

@property (nonatomic,strong)DataPickView *infoView;

@property (nonatomic,copy)NSString *shopName;
@property (nonatomic,copy)NSString *shopPhone;

//地址
@property (nonatomic,copy)NSString *lat;
@property (nonatomic,copy)NSString *lon;

//分类
@property (nonatomic,copy)NSString *Management;
//上传
@property (nonatomic,copy)NSString *shopPhoto;
@property (nonatomic,copy)NSString *positivePhoto;
@property (nonatomic,copy)NSString *negativePhoto;
@property (nonatomic,copy)NSString *elcPhoto;
//销售人员
@property (nonatomic,copy)NSString *ContactsName;
@property (nonatomic,copy)NSString *ContactsPhone;
@property (nonatomic,copy)NSString *ContactsCode;

@property (nonatomic,weak)UIButton *peopleCode;

@property (nonatomic,assign)NSInteger photoType;
@end

@implementation BusinessSettledController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = @"商家入驻";

    _elcPhoto = @"";
    _positivePhoto = @"";
    _negativePhoto = @"";
    _shopPhoto = @"";
    [self setUI];
    [AmapSlampLocationTool getLocationCoordinate:^(NSDictionary *locDict, BOOL isNew) {
    } error:^(NSError *error) {
    }];
}
- (void)setUI{
    
    __weak __typeof(&*self)weakSelf = self;
    UIScrollView *ScrollerV = [[UIScrollView alloc] init];
    [self.view addSubview:ScrollerV];
    
    UIView *mainV = [[UIView alloc] init];
    mainV.backgroundColor = [UIColor whiteColor];
    [ScrollerV addSubview:mainV];

    
    TextView *TextV = [TextView CreateArray:@[[TextModel Create:@"店铺名" detail:@"请输入店铺名" actualT:@"" Click:^(NSString *editText) {
        weakSelf.shopName = editText;
    }],[TextModel Create:@"店铺电话" detail:@"请输入店铺电话" actualT:@"" Click:^(NSString *editText) {
        weakSelf.shopPhone = editText;
    }]]];
    [mainV addSubview:TextV];
    _TextV = TextV;
    
    //店铺地址
    UILabel *shopL = [[UILabel alloc] init];
    shopL.text = @"店铺地址";
    shopL.font = [UIFont systemFontOfSize:14];
    [mainV addSubview:shopL];
    UITextField *shopAddressF = [[UITextField alloc] init];
    [shopAddressF addTarget:self action:@selector(editClick:) forControlEvents:UIControlEventEditingChanged];
    shopAddressF.placeholder = @"输入店铺地址";
    shopAddressF.delegate = self;
    shopAddressF.font = [UIFont systemFontOfSize:12];
    [mainV addSubview:shopAddressF];
    _shopAddressF = shopAddressF;
    UIImageView *lineImg = [[UIImageView alloc] init];
    lineImg.backgroundColor = DarkColor;
    [mainV addSubview:lineImg];
    UIButton *AddressB = [UIButton buttonWithType:UIButtonTypeCustom];
    [AddressB setImage:[UIImage imageNamed:@"per_address"] forState:UIControlStateNormal];
    AddressB.tag = BusinessAddress;
    [AddressB addTarget:self action:@selector(addresClick:) forControlEvents:UIControlEventTouchUpInside];
    [mainV addSubview:AddressB];
    _AddressB = AddressB;
    
    //经营类别
    UILabel *ManagementL = [[UILabel alloc] init];
    ManagementL.text = @"经营类别";
    ManagementL.font = [UIFont systemFontOfSize:14];
    [mainV addSubview:ManagementL];
    UIButton *ManagementB = [UIButton buttonWithType:UIButtonTypeCustom];
    [ManagementB setTitle:@"请选择经营类别" forState:UIControlStateNormal];
    ManagementB.titleLabel.font = [UIFont systemFontOfSize:12];
    [ManagementB setTitleColor:WYColor(202, 202, 207) forState:UIControlStateNormal];
    ManagementB.tag = BusinessCategory;
    ManagementB.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [ManagementB addTarget:self action:@selector(addresClick:) forControlEvents:UIControlEventTouchUpInside];
    [mainV addSubview:ManagementB];
    _ManagementB = ManagementB;
    UIImageView *lineTImg = [[UIImageView alloc] init];
    lineTImg.backgroundColor = DarkColor;
    [mainV addSubview:lineTImg];

    //上传图片
    UILabel *updateL = [[UILabel alloc] init];
    updateL.text = @"店铺图片";
    updateL.font = [UIFont systemFontOfSize:14];
    [mainV addSubview:updateL];
    UIButton *updateB = [UIButton buttonWithType:UIButtonTypeCustom];
    [updateB setTitle:@"上传图片" forState:UIControlStateNormal];
    updateB.titleLabel.font = [UIFont systemFontOfSize:12];
    [updateB setTitleColor:WYColor(202, 202, 207) forState:UIControlStateNormal];
    updateB.tag = Businessphoto;
    updateB.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [updateB addTarget:self action:@selector(addresClick:) forControlEvents:UIControlEventTouchUpInside];
    [mainV addSubview:updateB];
    _updateB = updateB;
   
    UIImageView *lineTHImg = [[UIImageView alloc] init];
    lineTHImg.backgroundColor = DarkColor;
    [mainV addSubview:lineTHImg];

    //身份证正面
    UILabel *positiveL = [[UILabel alloc] init];
    positiveL.text = @"身份证正面";
    positiveL.font = [UIFont systemFontOfSize:14];
    [mainV addSubview:positiveL];
    UIButton *positiveB = [UIButton buttonWithType:UIButtonTypeCustom];
    [positiveB setTitle:@"上传图片" forState:UIControlStateNormal];
    positiveB.titleLabel.font = [UIFont systemFontOfSize:12];
    [positiveB setTitleColor:WYColor(202, 202, 207) forState:UIControlStateNormal];
    positiveB.tag = Businesspositive;
    positiveB.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [positiveB addTarget:self action:@selector(addresClick:) forControlEvents:UIControlEventTouchUpInside];
    [mainV addSubview:positiveB];
    _positiveB = positiveB;

    UIImageView *lineFImg = [[UIImageView alloc] init];
    lineFImg.backgroundColor = DarkColor;
    [mainV addSubview:lineFImg];

    //身份证反面
    UILabel *negativeL = [[UILabel alloc] init];
    negativeL.text = @"身份证反面";
    negativeL.font = [UIFont systemFontOfSize:14];
    [mainV addSubview:negativeL];
    UIButton *negativeB = [UIButton buttonWithType:UIButtonTypeCustom];
    [negativeB setTitle:@"上传图片" forState:UIControlStateNormal];
    negativeB.titleLabel.font = [UIFont systemFontOfSize:12];
    [negativeB setTitleColor:WYColor(202, 202, 207) forState:UIControlStateNormal];
    negativeB.tag = Businessnegative;
    negativeB.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [negativeB addTarget:self action:@selector(addresClick:) forControlEvents:UIControlEventTouchUpInside];
    [mainV addSubview:negativeB];
    _negativeB = negativeB;

    UIImageView *lineFiveImg = [[UIImageView alloc] init];
    lineFiveImg.backgroundColor = DarkColor;
    [mainV addSubview:lineFiveImg];

    //营业执照
    UILabel *elcL = [[UILabel alloc] init];
    elcL.text = @"营业执照";
    elcL.font = [UIFont systemFontOfSize:14];
    [mainV addSubview:elcL];
    UIButton *elcB = [UIButton buttonWithType:UIButtonTypeCustom];
    [elcB setTitle:@"上传图片" forState:UIControlStateNormal];
    elcB.titleLabel.font = [UIFont systemFontOfSize:12];
    [elcB setTitleColor:WYColor(202, 202, 207) forState:UIControlStateNormal];
    elcB.tag = Businessnelc;
    elcB.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [elcB addTarget:self action:@selector(addresClick:) forControlEvents:UIControlEventTouchUpInside];
    [mainV addSubview:elcB];
    _elcB = elcB;

    
    UIImageView *bottomImg = [[UIImageView alloc] init];
    bottomImg.backgroundColor = DarkColor;
    [mainV addSubview:bottomImg];
    
    
    TextView *textTV = [TextView CreateArray:@[[TextModel Create:@"联系人" detail:@"请输入姓名" actualT:@"" Click:^(NSString *editText) {
        _ContactsName = editText;
        
    }],[TextModel Create:@"手机号" detail:@"请输入手机号" actualT:@"" Click:^(NSString *editText) {
        _ContactsPhone = editText;
        
    }]]];
    [mainV addSubview:textTV];
    _textTV = textTV;
    
    UIImageView *lineSixImg = [[UIImageView alloc] init];
    lineSixImg.backgroundColor = DarkColor;
    [mainV addSubview:lineSixImg];
    
    UILabel *peopleCodeL = [[UILabel alloc] init];
    peopleCodeL.text = @"编号";
    peopleCodeL.font = [UIFont systemFontOfSize:14];
    [mainV addSubview:peopleCodeL];
    UIButton *peopleCode = [UIButton buttonWithType:UIButtonTypeCustom];
    [peopleCode setTitle:@"请选择" forState:UIControlStateNormal];
    peopleCode.titleLabel.font = [UIFont systemFontOfSize:12];
    [peopleCode setTitleColor:WYColor(202, 202, 207) forState:UIControlStateNormal];
    peopleCode.tag = BusinessCode;
    peopleCode.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [peopleCode addTarget:self action:@selector(addresClick:) forControlEvents:UIControlEventTouchUpInside];
    [mainV addSubview:peopleCode];
    _peopleCode = peopleCode;

    
    
    UIButton *SubmitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [SubmitBtn setTitle:@"提交申请" forState:UIControlStateNormal];
    [SubmitBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    SubmitBtn.layer.cornerRadius = 3;
    SubmitBtn.tag = BusinessSub;
    SubmitBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [SubmitBtn addTarget:self action:@selector(addresClick:) forControlEvents:UIControlEventTouchUpInside];
    [SubmitBtn setBackgroundColor:KOrange];
    [self.view addSubview:SubmitBtn];
    _SubmitBtn = SubmitBtn;

    
    [ScrollerV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(weakSelf.view);
    }];
    
    [mainV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(ScrollerV);
        make.width.equalTo(ScrollerV);
    }];
    [TextV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(mainV);
        make.height.equalTo(@80);
    }];
    [shopL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(shopAddressF.mas_centerY);
        make.left.equalTo(mainV.mas_left).offset(8);
        make.size.mas_equalTo(CGSizeMake(80, 30));
    }];
    [AddressB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(shopL.mas_centerY);
        make.right.equalTo(mainV.mas_right).offset(-8);
        make.size.mas_equalTo(CGSizeMake(32, 32));
    }];
    [shopAddressF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(TextV.mas_bottom);
        make.left.equalTo(shopL.mas_right).offset(8);
        make.right.equalTo(AddressB.mas_left).offset(-8);
        make.height.equalTo(@39);
    }];
    [lineImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(shopL.mas_left);
        make.right.equalTo(AddressB.mas_right);
        make.top.equalTo(shopAddressF.mas_bottom).offset(0);
        make.height.equalTo(@1);
    }];

    [ManagementL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(ManagementB.mas_centerY);
        make.left.equalTo(mainV.mas_left).offset(8);
        make.size.mas_equalTo(CGSizeMake(80, 30));
    }];
    [ManagementB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lineImg.mas_bottom);
        make.right.equalTo(mainV.mas_right).offset(-8);
        make.left.equalTo(ManagementL.mas_right).offset(8);
        make.height.equalTo(@35);
    }];
    [lineTImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(shopL.mas_left);
        make.right.equalTo(lineImg.mas_right);
        make.top.equalTo(ManagementB.mas_bottom).offset(0);
        make.height.equalTo(@1);
    }];

    [updateL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(updateB.mas_centerY);
        make.left.equalTo(mainV.mas_left).offset(8);
        make.size.mas_equalTo(CGSizeMake(80, 30));
    }];
    [updateB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lineTImg.mas_bottom);
        make.right.equalTo(mainV.mas_right).offset(-8);
        make.left.equalTo(updateL.mas_right).offset(8);
        make.height.equalTo(@35);
    }];
    
    [lineTHImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(shopL.mas_left);
        make.right.equalTo(lineImg.mas_right);
        make.top.equalTo(updateB.mas_bottom).offset(0);
        make.height.equalTo(@1);
    }];

    [positiveL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(positiveB.mas_centerY);
        make.left.equalTo(mainV.mas_left).offset(8);
        make.size.mas_equalTo(CGSizeMake(80, 30));
    }];
    [positiveB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lineTHImg.mas_bottom);
        make.right.equalTo(mainV.mas_right).offset(-8);
        make.left.equalTo(positiveL.mas_right).offset(8);
        make.height.equalTo(@35);
    }];
    
    
    [lineFImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(shopL.mas_left);
        make.right.equalTo(lineImg.mas_right);
        make.top.equalTo(positiveB.mas_bottom).offset(0);
        make.height.equalTo(@1);
    }];
    
    [negativeL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(negativeB.mas_centerY);
        make.left.equalTo(mainV.mas_left).offset(8);
        make.size.mas_equalTo(CGSizeMake(80, 30));
    }];
    [negativeB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lineFImg.mas_bottom);
        make.right.equalTo(mainV.mas_right).offset(-8);
        make.left.equalTo(negativeL.mas_right).offset(8);
        make.height.equalTo(@35);
    }];
    
    
    [lineFiveImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(shopL.mas_left);
        make.right.equalTo(lineImg.mas_right);
        make.top.equalTo(negativeB.mas_bottom).offset(0);
        make.height.equalTo(@1);
    }];
    
    [elcL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(elcB.mas_centerY);
        make.left.equalTo(mainV.mas_left).offset(8);
        make.size.mas_equalTo(CGSizeMake(80, 30));
    }];
    [elcB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lineFiveImg.mas_bottom);
        make.right.equalTo(mainV.mas_right).offset(-8);
        make.left.equalTo(elcL.mas_right).offset(8);
        make.height.equalTo(@35);
    }];
    
    
    [bottomImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(mainV);
        make.top.equalTo(elcB.mas_bottom);
        make.height.equalTo(@6);
    }];
    [textTV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bottomImg.mas_bottom);
        make.left.right.equalTo(mainV);
        make.height.equalTo(@80);
    }];
    
    [lineSixImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(shopL.mas_left);
        make.right.equalTo(AddressB.mas_right);
        make.top.equalTo(textTV.mas_bottom).offset(0);
        make.height.equalTo(@1);
    }];
    [peopleCodeL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(peopleCode.mas_centerY);
        make.left.equalTo(mainV.mas_left).offset(8);
        make.size.mas_equalTo(CGSizeMake(80, 30));
    }];
    [peopleCode mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lineSixImg.mas_bottom);
        make.right.equalTo(mainV.mas_right).offset(-8);
        make.left.equalTo(peopleCodeL.mas_right).offset(8);
        make.height.equalTo(@35);
    }];
    
    [mainV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(peopleCode.mas_bottom);
    }];
    [SubmitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(mainV.mas_bottom).offset(12);
        make.left.equalTo(weakSelf.view.mas_left).offset(12);
        make.right.equalTo(weakSelf.view.mas_right).offset(-12);
        make.height.equalTo(@35);
    }];
}

#pragma mark - delegate
- (void)editClick:(UITextField *)field{


}
- (void)addresClick:(UIButton *)btn{
    [self.view endEditing:YES];
    __weak __typeof(&*self)weakSelf = self;
    switch (btn.tag) {
        case BusinessAddress:
        {
            if (![AmapSlampLocationTool GetLocationOpen]) {
                [ZYUserDefaults removeObjectForKey:CBYlatitude];
                [ZYUserDefaults removeObjectForKey:CBYlongitude];
                [ZYUserDefaults synchronize];
                [SCTool showAlerts:@"请前往设置打开定位" Ok:^(id alerts) {
                    [SCTool showSetting];
                } Cancel:^(id alerts) {
                }];
                return;
            }

            SCLocationController *pointVC = [[SCLocationController alloc] init];
            pointVC.Maddress = ^(NSDictionary *addDic) {
                weakSelf.lat = [addDic hw_safeObjectForKey:@"lat"];
                weakSelf.lon = [addDic hw_safeObjectForKey:@"lon"];
                weakSelf.shopAddressF.text = [addDic objectForKey:@"city"];
            };
            [weakSelf.navigationController pushViewController:pointVC animated:YES];
        }
            break;
        case Businessphoto:
        {
            weakSelf.photoType = 1;
            [weakSelf updatePhoto];
        }
            break;
        case Businesspositive:
        {
            weakSelf.photoType = 2;
            [weakSelf updatePhoto];
        }
            break;
        case Businessnegative:
        {
            weakSelf.photoType = 3;
            [weakSelf updatePhoto];
        }
            break;
        case Businessnelc:
        {
            weakSelf.photoType = 4;
            [weakSelf updatePhoto];
        }
            break;
            case BusinessCategory:
        {
            [weakSelf showPick:1];
        }
            break;
            case BusinessSub:
        {
            [weakSelf sub];
        }
            break;
        case BusinessCode:
        {
            [weakSelf showPick:2];
        }
            break;
        default:
            break;
    }
    
}
- (void)showPick:(NSInteger )type{
    __weak __typeof(&*self)weakSelf = self;
    _infoView = [[DataPickView alloc] initWithFrame:CGRectMake(0, KHeight, kWidth, 220)];
    if (type == 1) {
        _infoView.dataArr = [ZYUserDefaults objectForKey:KGoodsclass];
        _infoView.dataType = 1;
    }else if(type == 2){
        _infoView.dataArr = [ZYUserDefaults objectForKey:KBdList];
        _infoView.dataType = 2;
    }
    
    _infoView.types = @"normal";
    _infoView.Gclass = ^(NSDictionary *dic) {
        if ([dic hw_safeObjectForKey:@"bd_id"]) {
            weakSelf.ContactsCode = [NSString stringWithFormat:@"%@",[dic hw_safeObjectForKey:@"bd_id"]];
            [weakSelf.peopleCode setTitle:dic[@"bd_name"] forState:UIControlStateNormal];
            [weakSelf.peopleCode setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

        }else{
            [weakSelf.ManagementB setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

            weakSelf.Management = [NSString stringWithFormat:@"%@",[dic hw_safeObjectForKey:@"gc_id"]];
            [weakSelf.ManagementB setTitle:dic[@"gc_name"] forState:UIControlStateNormal];
        }
    };
    [_infoView show];
}
- (void)updatePhoto{
    __weak __typeof(&*self)weakSelf = self;
    ALActionSheetView *actionSheetV = [ALActionSheetView
                                       showActionSheetWithTitle:@"上传照片"
                                       cancelButtonTitle:@"取消"
                                       destructiveButtonTitle:nil
                                       otherButtonTitles:@[@"从相册选择",@"拍照"]
                                       handler:^(ALActionSheetView *actionSheetView, NSInteger buttonIndex) {
                                           if(buttonIndex == 0){
                                               [weakSelf localPhoto];
                                           }else if(buttonIndex == 1){
                                               [weakSelf takePhoto];
                                           }
                                       }];
    
    [actionSheetV show];

}
//开始拍照
-(void)takePhoto
{
    UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
        UIImagePickerController *picker = [[UIImagePickerController alloc]init];
        picker.delegate = self;
        //设置拍照后的图片可被编辑
        picker.allowsEditing = NO;
        picker.sourceType = sourceType;
        [self presentViewController:picker animated:YES completion:nil];
        
    }else{
        DLog(@"模拟机中无法打开照相机,请在真机中使用");
    }
}

//打开相册，可以多选
-(void)localPhoto
{
    ZYQAssetPickerController *picker = [[ZYQAssetPickerController alloc]init];
    picker.maximumNumberOfSelection = 1;
    picker.assetsFilter = ZYQAssetsFilterAllAssets;
    picker.showEmptyGroups = NO;
    picker.delegate = self;
    picker.selectionFilter = [NSPredicate predicateWithBlock:^BOOL(id evaluatedObject,NSDictionary *bindings){
        if ([(ZYQAsset*)evaluatedObject mediaType]==ZYQAssetMediaTypeVideo) {
            NSTimeInterval duration = [(ZYQAsset*)evaluatedObject duration];
            return duration >= 1;
        } else {
            return YES;
        }
    }];
    [self presentViewController:picker animated:YES completion:nil];
    
}
#pragma mark - ZYQAssetPickerController Delegate
-(void)assetPickerController:(ZYQAssetPickerController *)picker didFinishPickingAssets:(NSArray *)assets{
    
    if([assets count] == 0){
        return;
    }
    __block NSMutableArray *files = [NSMutableArray array];
    int idx = 1;
    __weak __typeof(&*self)weakSelf = self;
    for (ZYQAsset *asset in assets) {
        
        [asset setGetFullScreenImage:^(UIImage *resultImg) {
            dispatch_async(dispatch_get_main_queue(), ^{
                NSData *imageData=UIImageJPEGRepresentation(resultImg, 0.5);
                 NSDictionary *fileDic = @{@"data":imageData,@"name":@"file",@"mimeType":@"image/jpep",@"filename":[NSString stringWithFormat:@"@%d.jpeg",idx]};                [files addObject:fileDic];
            });
        }];
        idx ++;
    }
    
    [picker dismissViewControllerAnimated:YES completion:^{
        
        [SCTool showLoading:@"正在上传"];
        [SCApiTool ScUpdatePhoto:files token:_token Success:^(NSArray *data) {
            
             [SCTool showMessage:@"上传成功"];
            if (weakSelf.photoType == 1) {
                weakSelf.shopPhoto = [NSString stringWithFormat:@"%@",data.lastObject];
                [weakSelf.updateB setTitle:@"已选择" forState:UIControlStateNormal];
                [weakSelf.updateB setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                
            }else if (weakSelf.photoType == 2){
                weakSelf.positivePhoto = [NSString stringWithFormat:@"%@",data.lastObject];
                [weakSelf.positiveB setTitle:@"已选择" forState:UIControlStateNormal];
                [weakSelf.positiveB setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

            }else if (weakSelf.photoType == 3){
                weakSelf.negativePhoto = [NSString stringWithFormat:@"%@",data.lastObject];
                [weakSelf.negativeB setTitle:@"已选择" forState:UIControlStateNormal];
                [weakSelf.negativeB setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

            }else if (weakSelf.photoType == 4){
                weakSelf.elcPhoto = [NSString stringWithFormat:@"%@",data.lastObject];
                [weakSelf.elcB setTitle:@"已选择" forState:UIControlStateNormal];
                [weakSelf.elcB setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

            }
            
        } failure:^(NSString *errormsg) {
             [SCTool showError:errormsg];
        }];
    }];
}
- (void)assetPickerControllerDidMaximum:(ZYQAssetPickerController *)picker
{
    [SCTool showAlerts:@"超过照片最大上传数量"];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info {
    
    UIImage *img = [info valueForKey:UIImagePickerControllerOriginalImage];
    NSData *imageData = UIImageJPEGRepresentation(img, 0.5);
    NSDictionary *fileDic = @{@"data":imageData,@"name":@"file",@"mimeType":@"image/jpep",@"filename":@"1.jpeg"};
    __weak __typeof(&*self)weakSelf = self;
    
    [picker dismissViewControllerAnimated:YES completion:^{
        [SCTool showLoading:@"正在上传"];
        [SCApiTool ScUpdatePhoto:@[fileDic] token:_token Success:^(NSArray *data) {
            
            [SCTool showMessage:@"上传成功"];
            if (weakSelf.photoType == 1) {
                weakSelf.shopPhoto = [NSString stringWithFormat:@"%@",data.lastObject];
                [weakSelf.updateB setTitle:@"已选择" forState:UIControlStateNormal];
                [weakSelf.updateB setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                
            }else if (weakSelf.photoType == 2){
                weakSelf.positivePhoto = [NSString stringWithFormat:@"%@",data.lastObject];
                [weakSelf.positiveB setTitle:@"已选择" forState:UIControlStateNormal];
                [weakSelf.positiveB setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                
            }else if (weakSelf.photoType == 3){
                weakSelf.negativePhoto = [NSString stringWithFormat:@"%@",data.lastObject];
                [weakSelf.negativeB setTitle:@"已选择" forState:UIControlStateNormal];
                [weakSelf.negativeB setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                
            }else if (weakSelf.photoType == 4){
                weakSelf.elcPhoto = [NSString stringWithFormat:@"%@",data.lastObject];
                [weakSelf.elcB setTitle:@"已选择" forState:UIControlStateNormal];
                [weakSelf.elcB setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                
            }
            
        } failure:^(NSString *errormsg) {
            DLog(@"%@",errormsg);
            [SCTool showError:errormsg];
        }];
    }];
    
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    [picker dismissViewControllerAnimated:YES completion:^{
        
    }];
}
#pragma mark - 提交申请
- (void)sub{
    
    [self.view endEditing:YES];

    if (_lat.length == 0 ) {
        _lat = [NSString stringWithFormat:@"%@",[ZYUserDefaults objectForKey:CBYlatitude]];
    }
    if (_lon.length == 0) {
        _lon = [NSString stringWithFormat:@"%@",[ZYUserDefaults objectForKey:CBYlongitude]];
    }
    if (_shopName.length==0) {
        [SCTool showError:@"请输入门店名称"];
        return;
    }
    if (_shopPhone.length==0) {
        [SCTool showError:@"请输入电话号码"];
        return;
    }
    if (_shopAddressF.text.length==0) {
        [SCTool showError:@"请输入门店地址"];
        return;
    }
    if (_Management.length==0) {
        [SCTool showError:@"请选择经营类别"];
        return;
    }
    /*
    if (_shopPhoto.length==0) {
        [SCTool showError:@"请选择店铺图片"];
        return;
    }
    if (_positivePhoto.length==0) {
        [SCTool showError:@"请选择身份证正面照片"];
        return;
    }
    if (_negativePhoto.length==0) {
        [SCTool showError:@"请选择身份证反面照片"];
        return;
    }
    if (_elcPhoto.length==0) {
        [SCTool showError:@"请选择营业执照"];
        return;
    }
     */
    if (_ContactsName.length==0) {
        [SCTool showError:@"请选择联系人"];
        return;
    }
    if (_ContactsPhone.length==0) {
        [SCTool showError:@"请输入手机号"];
        return;
    }
    if (_ContactsCode.length==0) {
        [SCTool showError:@"请选择销售人员编号"];
        return;
    }
    [SCTool showLoading:@"正在申请入驻"];
    __weak __typeof(&*self)weakSelf = self;
    [SCApiTool ScJoininStore_name:_shopName
                      store_phone:_shopPhone
                    store_address:_shopAddressF.text
                     coordinate_x:_lon
                     coordinate_y:_lat
      business_licence_number_elc:_elcPhoto business_licence_id_number_positive:_positivePhoto
business_licence_id_number_negative:_negativePhoto
                      store_label:_shopPhoto
                            bd_id:_ContactsCode
                    contacts_name:_ContactsName
                   contacts_phone:_ContactsPhone
                            token:_token
                          success:^(NSString *msg) {
                       
                       [SCTool showSuccess:msg];
                       
                       dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                        BusinessTypeController *typeVC = [[BusinessTypeController alloc] init];
                        [weakSelf.navigationController pushViewController:typeVC animated:YES];

                       });
                      } failure:^(NSString *errormsg) {
                          
                          [SCTool showError:errormsg];
                      }];
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];

}


@end
